Imports System.Collections.Generic
Imports System.Text
Public Class DbfTable
    Friend mDbfFile As Core.DbfFile
    Public Sub New(filePath As String, encoding As System.Text.Encoding, version As DbfVersion)
        mDbfFile = Core.DbfFile.[Get](filePath, encoding, version)
    End Sub

    Protected Sub New()
    End Sub

    Public Function GetRecord(rowNo As Int32) As DbfRecord
        Return DirectCast(mDbfFile.InternalGetRecord(rowNo, False), DbfRecord)
    End Function

    Public ReadOnly Property RecordCount() As Integer
        Get
            Return CInt(mDbfFile.RecordCount)
        End Get
    End Property

    Public Function GetIndex(filepath As String, sortOrder As SortOrder) As DbfIndex
        Return mDbfFile.GetIndex(filepath, sortOrder)
    End Function

    Public ReadOnly Property Columns() As List(Of Core.ColumnDefinition)
        Get
            Return mDbfFile.Columns
        End Get
    End Property


End Class

Public Class DbfTable(Of TRecord As {DbfRecord, New})
	Inherits DbfTable
	Implements IEnumerable(Of TRecord)
	Friend Shadows mDbfFile As Core.DbfFile(Of TRecord)

	Public Sub New(filePath As String, encoding As System.Text.Encoding, version As DbfVersion)
		mDbfFile = Core.DbfFile(Of TRecord).[Get](filePath, encoding, version)
		MyBase.mDbfFile = mDbfFile
	End Sub

	Public Function NewRecord() As TRecord
		Return mDbfFile.NewRecord()
	End Function

	#Region "IEnumerable<TRecord> Members"

	Public Function GetEnumerator() As IEnumerator(Of TRecord) Implements IEnumerable(Of TRecord).GetEnumerator
		Return mDbfFile.GetEnumerator()
	End Function

	Private Function System_Collections_IEnumerable_GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
		Return GetEnumerator()
	End Function

	#End Region

    Public Shadows Function GetRecord(p As Int32) As TRecord
        Return DirectCast(mDbfFile.InternalGetRecord(p, False), TRecord)
    End Function

	Public Sub Close()
		mDbfFile.StopReading()
		mDbfFile = Nothing
	End Sub

	Public Sub EmptyTable()
		mDbfFile.EmptyTable()
	End Sub

	Public Shadows Function GetIndex(filepath As String, sortOrder As SortOrder) As DbfIndex(Of TRecord)
		Return DirectCast(mDbfFile.GetIndex(filepath, sortOrder), DbfIndex(Of TRecord))
	End Function

End Class
